﻿namespace Oblivion.Networking.Packets
{
    public class EncryptionResponsePacket
    {
        private readonly Packet pkt;

        public byte[] SharedSecret = new byte[0];
        public short SharedSecretLength = 0;
        public byte[] VerifyToken = new byte[0];
        public short VerifyTokenLength = 0;

        public EncryptionResponsePacket(byte[] data)
        {
            pkt = new Packet(data);
            pkt.ReadPacketType();
            SharedSecretLength = pkt.ReadInt16();
            SharedSecret = pkt.ReadUInt8Array(SharedSecretLength);
            VerifyTokenLength = pkt.ReadInt16();
            VerifyToken = pkt.ReadUInt8Array(VerifyTokenLength);


            pkt.FinishReading();
        }

        public EncryptionResponsePacket()
        {
            pkt = new Packet(PacketType.EncryptionResponse);
        }

        public byte[] Build()
        {
            pkt.WriteInt16(SharedSecretLength);
            pkt.WriteUInt8Array(SharedSecret);
            pkt.WriteInt16(VerifyTokenLength);
            pkt.WriteUInt8Array(VerifyToken);

            return pkt.Finalize();
        }
    }
}